/*
 * GwtYuiCarousel - API to integrate YUI Carousel in GWT framework
 *
 * Copyright (c) 2007, Nicolas Hoppenot
 *
 * This free software is licensed under the Apache License, Version 2.0 (the "License").
 * To obtain a copy of the licence, visit : http://www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed WITHOUT ANY WARRANTY OR CONDITION OF ANY KIND.
 * Please see the license for more information.
 *
 * Version $0.6.1-beta1$
 */
package com.gwtyuicarousel.client.ui;

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;

/**
 * Create a carousel structure with the required carousel elements (cf
 * {@link RequiredCarouselStructure}). The next and previous controls can be easily added to the
 * structure.
 * 
 * @version $0.6.1-beta1$
 * @author Nicolas Hoppenot
 * 
 */
public class SimpleCarouselStructure
    extends RequiredCarouselStructure {

  /**
   * Permit to create a carousel structure integrating the next and previous controls. These next
   * and previous controls are {@link Widget} and are integrated within the carousel structure. It
   * is not necessary to set the nextElement and previousElement values in the carousel
   * configuration object. If these values have been set, it will be overwritten.
   * 
   * @param carouselId
   *          The ID of the root DIV element of the Carousel
   * @param nextElement
   *          The widget to use as next control.
   * @param prevElement
   *          The widget to use as previous control.
   * @param insertInCarouselDiv
   *          If true, nextElement and previousElement are not yet attached to a parent that is
   *          attached to the document.
   * @param config
   *          The carousel configuration properties
   */
  public SimpleCarouselStructure(String carouselId, Widget nextElement, Widget prevElement,
      boolean insertInCarouselDiv, CarouselConfig config) {
    super(carouselId);
    if (config == null) {
      config = new CarouselConfig();
    }
    this.config = config;
    if (insertInCarouselDiv) {
      add(prevElement, getElement());
      add(nextElement, getElement());
    }
    config.addNextElement(nextElement.getElement());
    config.addPrevElement(prevElement.getElement());
  }

  /**
   * Permit to create a carousel structure integrating the next and previous controls. These next
   * and previous controls are integrated within the carousel structure. It is not necessary to set
   * the nextElement and previousElement values in the carousel configuration object. If these
   * values have been set, it will be overwritten.
   * 
   * @param carouselId
   *          The ID of the root DIV element of the Carousel
   * @param nextElement
   *          The widget to use as next control
   * @param prevElement
   *          The widget to use as previous control
   * @param insertInCarouselDiv
   *          If true, nextElement and previousElement are not yet attached to a parent that is
   *          attached to the document.
   */
  public SimpleCarouselStructure(String carouselId, Widget nextElement, Widget prevElement,
      boolean insertInCarouselDiv) {
    this(carouselId, nextElement, prevElement, insertInCarouselDiv, null);
  }

  /**
   * Permit to create a carousel structure integrating the next and previous controls. These next
   * and previous controls are HTML element ({@link Element}) are integrated within the carousel
   * structure. It is not necessary to set the nextElement and previousElement values in the
   * carousel configuration object. If these values have been set, it will be overwritten.
   * 
   * @param carouselId
   *          The ID of the root DIV element of the Carousel
   * @param nextElement
   *          The HTML element to use as next control.
   * @param prevElement
   *          The HTML element to use as previous control.
   * @param config
   *          The carousel configuration properties
   */
  public SimpleCarouselStructure(String carouselId, Element nextElement, Element prevElement,
      CarouselConfig config) {
    super(carouselId);
    this.config = config;
    if (config == null) {
      config = new CarouselConfig();
    }
    config.addNextElement(nextElement);
    config.addPrevElement(prevElement);
  }

}
